package com.example.cofeed.activity;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.cofeed.adapter.NoteAdapter;
import com.example.cofeed.api.ApiService;
import com.example.cofeed.base.BaseListActivity;
import com.example.cofeed.callback.DialogCallback;
import com.example.cofeed.callback.LzyResponse;
import com.example.cofeed.constant.IntentKeyConstant;
import com.example.cofeed.entity.Msg;
import com.lzy.okgo.model.Response;
import com.umeng.analytics.MobclickAgent;

import java.util.List;
import java.util.Map;

/**
 * Created by mqwang on 2017/9/26.
 */

public class MyCollectActivity extends BaseListActivity<Msg> {

    private NoteAdapter granaryAdapter;

    @Override
    protected void bindRecyclerView(RecyclerView recyclerView) {
        setMainTitle("我的收藏");
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(linearLayoutManager);
        granaryAdapter = new NoteAdapter();
        recyclerView.setAdapter(granaryAdapter);

//        granaryAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
//            @Override
//            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
//                Msg msg = (Msg) adapter.getData().get(position);
//                Intent intent = new Intent(MyCollectActivity.this, DetailsActivity.class);
//                intent.putExtra(IntentKeyConstant.MSG_ID, msg.smsid);
//                startActivity(intent);
//            }
//        });
//        granaryAdapter.setMenu(1);
        granaryAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, final int position) {
//                Msg msg = (Msg) adapter.getData().get(position);
//                ApiService.favoriteDelete(msg.smsid, new DialogCallback<LzyResponse<Map<String, String>>>() {
//                    @Override
//                    public void onSuccess(Response<LzyResponse<Map<String, String>>> response) {
//                        granaryAdapter.remove(position);
//                        showToast(response.body().message);
//
//                    }
//                });
                Msg msg = (Msg) adapter.getData().get(position);
                Intent intent = new Intent(MyCollectActivity.this, DetailsActivity.class);
                intent.putExtra(IntentKeyConstant.MSG_ID, msg.smsid);
                startActivity(intent);
            }
        });

        refreshLayout.setEnableLoadMore(false);

    }

    @Override
    protected void loadData(int page, int pageCount) {
        ApiService.favorite_list_favor_jiu(this, new DialogCallback<LzyResponse<List<Msg>>>() {
            @Override
            public void onSuccess(Response<LzyResponse<List<Msg>>> response) {
                onGetDataSuc(response.body().data);
//                disableLoadMore();
            }
        });
    }

    @Override
    protected void bindData(boolean isRefreshMode, List<Msg> data) {
        granaryAdapter.setNewData(data);
    }

    @Override
    protected List<Msg> getData() {
        return granaryAdapter.getData();
    }

    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }
}
